package xyz.shu.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.shu.common.ApplicationContextHelper;
import xyz.shu.common.JsonData;
import xyz.shu.dao.SysAclModuleMapper;
import xyz.shu.exception.ParamException;
import xyz.shu.model.SysAclModule;
import xyz.shu.param.TestVo;
import xyz.shu.util.BeanValidator;
import xyz.shu.util.JsonMapper;

/**
 * @author shujinhao
 */
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {
    @RequestMapping("/hello.json")
    @ResponseBody
    public JsonData hello(){
        log.info("hello你好");
        throw new RuntimeException("test exception");
//        return JsonData.success("hello ,permission");
    }


    @RequestMapping("/validate.json")
    @ResponseBody
    public JsonData validate(TestVo testVo) throws ParamException {
        log.info("validate");

        SysAclModuleMapper sysAclModuleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule sysAclModule = sysAclModuleMapper.selectByPrimaryKey(1);
        log.info(JsonMapper.obj2String(sysAclModule));
        BeanValidator.check(testVo);
        return JsonData.success("test ,validate");
    }
}
